<?php
$id				= gpc_getIntPost("id",$id);
$parentId       = gpc_getIntPost("ParentId");
$name	        = gpc_getStringPost("Name");
$type	        = gpc_getStringPost("Type");
$status	        = gpc_getIntPost("Status");
$content        = gpc_getStringPost("Content");
$TopBottomOrder	= gpc_getIntPost("TopBottomOrder",-1);
$order 			= gpc_getIntPost("Order",-1);

//images:
$listname		= gpc_getStringArray("ListName");
$listurl		= gpc_getStringArray("ListUrl");
$listid			= gpc_getStringArray("ListId");
$listorder		= gpc_getStringArray("listorder");

$order          = GetOrderForInsert($TopBottomOrder,$order,$parentId,"tbltourtab");


if($act=="inserttab")
{
    $sql_insert = "insert into tbltourtab (iParentId,cName,cType,iStatus,iOrder)
                values($parentId,'$name','$type','$status','$order')";
    $dbsql->query($sql_insert);
    $idtab=$dbsql->insert_id();
    page_transfer("Add Tab Success","opt=edittab&id=$idtab");
}
else
{
    $sql_update = "update tbltourtab SET ";
    //$sql_update.= " iParentId   = '$parentId', ";
    $sql_update.= " cName       = '$name', ";
    //$sql_update.= " cType       = '$type', ";
    $sql_update.= " cIntro      = '$content',";
    if($order>0)
    {
        $sql_update.= " iOrder      = '$order',";
    }
    $sql_update.= " iStatus     = '$status' ";
    $sql_update.= " where iId   = '$id' ";

    $dbsql->query($sql_update);

    //insert if type is Image:
    foreach($listid as $i=> $idg)
    {
        $idg=intval($idg);
        if($listurl[$i]==-1 && $idg>0)
        {
            //echo $idg;exit;
            $sql_delete="delete from tblgallery where iId=$idg";
            $dbsql->query($sql_delete);
        }
        elseif($idg<=0)
        {
        	$sql_insert = "INSERT INTO tblgallery
        					(iParentId,cName,iStatus,cImage,iOrder,cType,cLanguage)
        				VALUE($id,'$listname[$i]','1','$listurl[$i]',1,'tourtab','$language')";

        	$dbsql->query($sql_insert);
        }
        else
        {
            $sql_update = "UPDATE tblgallery SET
                			 cName = '$listname[$i]'
                			 WHERE iId = '$idg'";
            $dbsql->query($sql_update);
        }
    }
    page_transfer("Update Tab Success","opt=tabs&id=$parentId");
}
?>